/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: XMQ
 * Date: 2022-05-11
 * Time: 8:57
 */
//代码块
class Student{
    //普通成员变量
    public String name;
    public int age;
    public double score;
    //静态成员变量
    public static String classes = "105java";//不属于对象  -》方法区


    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
        System.out.println("这是带三个参数的构造方法！");
    }
    {
//        this.name = "123";
        System.out.println("实例代码块！");
    }
    static {
        classes = "106";
        System.out.println("静态代码块！");
    }
    public void doClass(){
        System.out.println("去105上课");
        classes = "106";
    }
    //静态的方法当中，不能直接访问非静态的数据
    public static void staticWay(){
        //this.name = "123";
        System.out.println("这是一个静态的方法！-》类方法");
//        Student student = new Student("12",123,88.88);
//        student.name = "123";
    }
}
public class TestDemo {
    public static void main(String[] args) {
        //如果有实例化对象，先执行静态代码块->实例化代码块->构造方法
        System.out.println(Student.classes);
        Student stuent1 = new Student("liuyuhao",17,99.9);
//        System.out.println(stuent1.name);
        System.out.println("=================");
        Student stuent2 = new Student("zc",17,59.9);
//        System.out.println(stuent2.name);

    }
    public static void main1(String[] args) {

        Student student1 = new Student("liuyuhao",17,99.9);
        Student student2 = new Student("zc",17,59.9);
        System.out.println(student1.classes);//能通过对象访问
        System.out.println(Student.classes);//但是最好通过类名访问
        student2.staticWay();
        Student.staticWay();
    }
}
